/*
 * 项目名称:platform-plus
 * 类名称:NcpCumulativeOfCasesServiceImpl.java
 * 包名称:com.platform.modules.ncp.service.impl
 *
 * 修改履历:
 *     日期                       修正者        主要内容
 *     2020-02-11 18:03:21        tumin     初版做成
 *
 * Copyright (c) 2019-2019 微同软件
 */
package com.platform.modules.ncp.service.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.common.utils.Query;
import com.platform.modules.ncp.dao.NcpCumulativeOfCasesDao;
import com.platform.modules.ncp.entity.NcpCumulativeOfCasesEntity;
import com.platform.modules.ncp.service.NcpCumulativeOfCasesService;
import com.platform.modules.sys.entity.SysConfigEntity;
import com.platform.modules.utils.ShiroUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Wrapper;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Service实现类
 *
 * @author tumin
 * @date 2020-02-11 18:03:21
 */
@Service("ncpCumulativeOfCasesService")
public class NcpCumulativeOfCasesServiceImpl extends ServiceImpl<NcpCumulativeOfCasesDao, NcpCumulativeOfCasesEntity> implements NcpCumulativeOfCasesService {

    @Override
    public List<NcpCumulativeOfCasesEntity> queryAll(Map<String, Object> params) {
        params.put("createUserId", ShiroUtils.getUserId());
        return baseMapper.queryAll(params);
    }

    @Override
    public List<NcpCumulativeOfCasesEntity> queryAllYesterday(Map<String, Object> params) {
        Date date=DateUtil.yesterday();
        Date begin=DateUtil.beginOfDay(date);
        Date end=DateUtil.endOfDay(date);
        return baseMapper.selectList(new QueryWrapper<NcpCumulativeOfCasesEntity>().between("CREATE_TIME",DateUtil.formatDateTime(begin),DateUtil.formatDateTime(end)).eq("CREATE_USER_ID",ShiroUtils.getUserId()).orderByDesc("ID_NUMBER"));
    }

    @Override
    public List<NcpCumulativeOfCasesEntity> queryAllToday(Map<String, Object> params) {
        Date date=DateUtil.date();
        Date begin=DateUtil.beginOfDay(date);
        Date end=DateUtil.endOfDay(date);
        return baseMapper.selectList(new QueryWrapper<NcpCumulativeOfCasesEntity>().between("CREATE_TIME",DateUtil.formatDateTime(begin),DateUtil.formatDateTime(end)).eq("CREATE_USER_ID",ShiroUtils.getUserId()).orderByDesc("ID_NUMBER"));
    }

    @Override
    public Page queryPage(Map<String, Object> params) {
        //排序
        params.put("sidx", "T.PERS_ID");
        params.put("asc", false);
        params.put("createUserId", ShiroUtils.getUserId());
        Object po=params.get("createTime");
        Object to=params.get("type");
        String dateStr="";
        Date date=null;
        if(null!=po){
            dateStr=po.toString();
            date=DateUtil.parse(dateStr);
        }else{
            date=DateUtil.date();
        }
        Page<NcpCumulativeOfCasesEntity> page = new Query<NcpCumulativeOfCasesEntity>(params).getPage();
        Date begin=DateUtil.beginOfDay(date);
        Date end=DateUtil.endOfDay(date);
        QueryWrapper<NcpCumulativeOfCasesEntity> queryWrapper=new QueryWrapper<NcpCumulativeOfCasesEntity>().between("CREATE_TIME",DateUtil.formatDateTime(begin),DateUtil.formatDateTime(end));
        queryWrapper=queryWrapper.eq("CREATE_USER_ID",ShiroUtils.getUserId());
        if(null!=to){
            int typInt=Integer.parseInt(to.toString());
            queryWrapper=queryWrapper.eq("CASES_CLASSIFICATION",typInt);
        }
        queryWrapper=queryWrapper.orderByDesc("ID_NUMBER");
        return (Page) baseMapper.selectPage(page,queryWrapper);
//        return page.setRecords(baseMapper.selectNcpCumulativeOfCasesPage(page, params));
    }

    @Override
    public boolean add(NcpCumulativeOfCasesEntity ncpCumulativeOfCases) {
        return this.save(ncpCumulativeOfCases);
    }

    @Override
    public boolean update(NcpCumulativeOfCasesEntity ncpCumulativeOfCases) {
        return this.updateById(ncpCumulativeOfCases);
    }

    @Override
    public boolean delete(String persId) {
        return this.removeById(persId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteBatch(String[] persIds) {
        return this.removeByIds(Arrays.asList(persIds));
    }
}
